/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainUI.java
 *
 * Created on 12/05/2011, 12:48:04
 */
package br.com.softnight.ui;

import br.com.softnight.dao.VendaDAO;
import br.com.softnight.db.DBUtil;
import br.com.softnight.entidades.Venda;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Franklin
 */
public class MainUI extends javax.swing.JFrame {

    /** Creates new form MainUI */
    public MainUI() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        barraStatus = new javax.swing.JLabel();
        jToolBar1 = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        menuCadastros = new javax.swing.JMenu();
        menuItemCadastroClientes = new javax.swing.JMenuItem();
        menuItemCadastroProdutos = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        menuMovimentacoes = new javax.swing.JMenu();
        menuItemNovaVenda = new javax.swing.JMenuItem();
        menuItemNovaCompra = new javax.swing.JMenuItem();
        menuRelatorios = new javax.swing.JMenu();
        menuItemRelatorioVendas = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        contentsMenuItem = new javax.swing.JMenuItem();
        aboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        barraStatus.setFont(new java.awt.Font("Arial", 1, 11));
        barraStatus.setText("Usuário de Avaliação");
        barraStatus.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jToolBar1.setRollover(true);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/softnight/img/ICONVENDAS2.jpg"))); // NOI18N
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton1);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/softnight/img/ICONCOMPRAS2.jpg"))); // NOI18N
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setMaximumSize(new java.awt.Dimension(55, 55));
        jButton2.setMinimumSize(new java.awt.Dimension(55, 55));
        jButton2.setPreferredSize(new java.awt.Dimension(55, 55));
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton2);

        menuCadastros.setMnemonic('f');
        menuCadastros.setText("Cadastros");

        menuItemCadastroClientes.setMnemonic('o');
        menuItemCadastroClientes.setText("Clientes");
        menuItemCadastroClientes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemCadastroClientesActionPerformed(evt);
            }
        });
        menuCadastros.add(menuItemCadastroClientes);

        menuItemCadastroProdutos.setMnemonic('s');
        menuItemCadastroProdutos.setText("Produtos");
        menuItemCadastroProdutos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemCadastroProdutosActionPerformed(evt);
            }
        });
        menuCadastros.add(menuItemCadastroProdutos);

        exitMenuItem.setMnemonic('x');
        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        menuCadastros.add(exitMenuItem);

        menuBar.add(menuCadastros);

        menuMovimentacoes.setMnemonic('e');
        menuMovimentacoes.setText("Movimentações");

        menuItemNovaVenda.setMnemonic('v');
        menuItemNovaVenda.setText("Nova Venda");
        menuItemNovaVenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemNovaVendaActionPerformed(evt);
            }
        });
        menuMovimentacoes.add(menuItemNovaVenda);

        menuItemNovaCompra.setMnemonic('c');
        menuItemNovaCompra.setText("Nova Compra");
        menuItemNovaCompra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemNovaCompraActionPerformed(evt);
            }
        });
        menuMovimentacoes.add(menuItemNovaCompra);

        menuBar.add(menuMovimentacoes);

        menuRelatorios.setText("Relatórios");

        menuItemRelatorioVendas.setText("Vendas");
        menuItemRelatorioVendas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemRelatorioVendasActionPerformed(evt);
            }
        });
        menuRelatorios.add(menuItemRelatorioVendas);

        menuBar.add(menuRelatorios);

        helpMenu.setMnemonic('h');
        helpMenu.setText("Help");

        contentsMenuItem.setMnemonic('c');
        contentsMenuItem.setText("Contents");
        helpMenu.add(contentsMenuItem);

        aboutMenuItem.setMnemonic('a');
        aboutMenuItem.setText("About");
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(barraStatus, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 204, Short.MAX_VALUE)
                .addComponent(barraStatus))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void menuItemCadastroClientesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemCadastroClientesActionPerformed
        try {
            new ClienteBrowser(null, true).abre();
        } catch (SQLException ex) {
            Logger.getLogger(MainUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_menuItemCadastroClientesActionPerformed

    private void menuItemNovaVendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemNovaVendaActionPerformed
        try {
            Venda venda = new Venda();
            venda.setId(DBUtil.nextID());
            
            VendaEdicao vendaEdicao = new VendaEdicao(null, true);
            vendaEdicao.edita(venda);

            VendaDAO vendaDAO = new VendaDAO();
            vendaDAO.insere(venda);

            vendaEdicao = null;
            
        } catch (SQLException ex) {
            Logger.getLogger(MainUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_menuItemNovaVendaActionPerformed

    private void menuItemCadastroProdutosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemCadastroProdutosActionPerformed
        try {
            new ProdutoBrowser(null, true).abre();
        } catch (SQLException ex) {
            Logger.getLogger(MainUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_menuItemCadastroProdutosActionPerformed

    private void menuItemNovaCompraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemNovaCompraActionPerformed
    }//GEN-LAST:event_menuItemNovaCompraActionPerformed

    private void menuItemRelatorioVendasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemRelatorioVendasActionPerformed
        VendaConsulta vendaConsulta = new VendaConsulta(this, true);
        try {
            vendaConsulta.abre();
        } catch (SQLException ex) {
            Logger.getLogger(MainUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_menuItemRelatorioVendasActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JLabel barraStatus;
    private javax.swing.JMenuItem contentsMenuItem;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenu menuCadastros;
    private javax.swing.JMenuItem menuItemCadastroClientes;
    private javax.swing.JMenuItem menuItemCadastroProdutos;
    private javax.swing.JMenuItem menuItemNovaCompra;
    private javax.swing.JMenuItem menuItemNovaVenda;
    private javax.swing.JMenuItem menuItemRelatorioVendas;
    private javax.swing.JMenu menuMovimentacoes;
    private javax.swing.JMenu menuRelatorios;
    // End of variables declaration//GEN-END:variables
}
